﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using LunwenYun.Infrastructure.Entities.Repository;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class MessageBoard : IAccessible<T_MessageBoard, MessageBoard>, ILogicEntity<T_MessageBoard, MessageBoard>
    {
        #region
        public int Id { get; set; }
        /// <summary>
        /// 1：论文 1：投稿意向
        /// </summary>
        public int To { get; set; }
        /// <summary>
        /// 1：留言 2：私信
        /// </summary>
        public int MessageType { get; set; }
        public int RelateId { get; set; }
        public string Message { get; set; }
        public DateTime CreateDate { get; set; }
        public string From { get; set; }
        public string FromName { get; set; }
        #endregion

        #region extend
        public Article Article { get; set; }
        public PaperAgentInfo AgentInfo { get; set; }
        #endregion

        protected override void Covariant(T_MessageBoard model)
        {
            if (model != null)
            {
                this.CreateDate = model.CreateDate;
                this.From = model.From;
                this.FromName = model.FromName;
                this.Id = model.Id;
                this.Message = model.Message;
                this.MessageType = model.MessageType;
                this.RelateId = model.RelateId;
                this.To = model.To;
            }
        }
        protected override T_MessageBoard Inverter(MessageBoard model)
        {
            if (model != null)
            {
                return new T_MessageBoard()
                {
                    CreateDate = model.CreateDate,
                    From = model.From,
                    FromName = model.FromName,
                    Id = model.Id,
                    Message = model.Message,
                    MessageType = model.MessageType,
                    RelateId = model.RelateId,
                    To = model.To
                };
            }
            return null;
        }
        public MessageBoard Set(T_MessageBoard dbModel)
        {
            if (dbModel != null)
            {
                Covariant(dbModel);
                return this;
            }
            return null;
        }

        public MessageBoard LoadArticle(Article article)
        {
            this.Article = article;
            return this;
        }
        public MessageBoard LoadArticle(T_Article t_article)
        {
            this.Article = new Article().Set(t_article);
            return this;
        }

        public MessageBoard LoadAgentInfo(PaperAgentInfo paperAgentInfo)
        {
            this.AgentInfo = paperAgentInfo;
            return this;
        }
        public MessageBoard LoadAgentInfo(T_PaperAgentInfo t_PaperAgentInfo)
        {
            this.AgentInfo = new PaperAgentInfo().Set(t_PaperAgentInfo);
            return this;
        }
    }
}
